#!/usr/bin/python
# -*-coding:utf-8-*-

'''
定义一些简单算子
'''

import numpy as np
from joblib import wrap_non_picklable_objects

import warnings

warnings.filterwarnings('ignore')

# gp_func_v1_arity_map = {
#     'max_logical_bool': 2,
#     'logical': 4,
#     'max_logical': 2,
#     'min_logical': 2,
#     'lrelu': 1,
#     'power2': 1,
#     'power3': 1,
#     'protect_abslog': 1,
# }

# 1
@wrap_non_picklable_objects
def def_max_logical_bool(x1, x2):
    ret_val = np.where(x1>x2, np.ones_like(x1), np.zeros_like(x1))
    ret_val[np.isnan(x1) | np.isnan(x2)] = np.nan
    return ret_val

# 2
@wrap_non_picklable_objects
def def_logical(x1, x2, x3, x4):
    ret_val = np.where(x1>x2, x3, x4)
    ret_val[np.isnan(x1) | np.isnan(x2)] = np.nan
    return ret_val

# 3
@wrap_non_picklable_objects
def def_max_logical(x1, x2):
    ret_val = np.where(x1>x2, x1,x2)
    ret_val[np.isnan(x1) | np.isnan(x2)] = np.nan
    return ret_val

# 4
@wrap_non_picklable_objects
def def_min_logical(x1, x2):
    ret_val = np.where(x1>x2, x2, x1)
    ret_val[np.isnan(x1) | np.isnan(x2)] = np.nan
    return ret_val

# @wrap_non_picklable_objects
# def exp2_c(x1):
#     return np.exp2(x1)

# 5
@wrap_non_picklable_objects
def def_lrelu(x):
    return np.where(x > 0, x, 0.1*x)

# @wrap_non_picklable_objects
# def sigmoid_c(x):
#     return 1/(1+np.exp(-x))

# 6
@wrap_non_picklable_objects
def def_power2(x):
    return np.power(x, 2)

# 7
def def_power3(x):
    return np.power(x, 3)

# 8  abs log plus 1 protect
@wrap_non_picklable_objects
def def_protect_abslog(x):
    return np.log(np.abs(x)+1)



